# 换行
snippet prn "换行 printf\n" b
printf("\n");
endsnippet

# 转换成相应
global !p
def tranFlag(flag,inp,sep=''):
	if flag == None:
		flag = 'd'
	if sep == None:
		sep = ''
	flag = '%'+flag
	
	return (len(inp.split())-1)*(flag+sep) + flag
endglobal

global !p
def tranSeq(inp,sep=''):
	a = inp.split()
	return sep+(','+sep).join(a)
endglobal

global !p
def tranSeq2(inp,sep=''):
	a = inp.split()
	temp= sep+','
	return temp.join(a)+sep
endglobal


# printf
# pr[flag] [t1] [t1] [t3] [blank]
snippet "pr(\w+)? ((\S+ )*\S+)( )?" "printf" br
printf("${1:`!p snip.rv=tranFlag(match.group(1),match.group(2),match.group(4))`}${2:\n}",`!p snip.rv=tranSeq(match.group(2))`);
endsnippet

# scanf
# sc[flag] t1 t2 t3
snippet "sc(\w+)? ((\S+ )*\S+)( )?" "scanf" ir
scanf("`!p snip.rv=tranFlag(match.group(1),match.group(2),match.group(4))`",`!p snip.rv=tranSeq(match.group(2),'' if match.group(1)=='s' else '&')`);
endsnippet


#F
snippet "F (\w+)?" "定义函数" br 
${1:int} `!p snip.rv=match.group(1)`(${2: 参数}){
	${0}
}
endsnippet

# int 定义变量
snippet "i ((\w+ )*\w+)" "int 定义" br
int `!p snip.rv=tranSeq(match.group(1))`;
endsnippet

# int 定义变量,初始化 i0 a b c => int a=0,b=0,c=0;
snippet "i(\d+) ((\w+ )*\w+)" "int 定义,初始化" br
int `!p snip.rv=tranSeq2(match.group(2),'='+match.group(1))`;
endsnippet

# simple code template
snippet sct "代码模板-简单" b
/* author: Rainboy  email: rainboylvx@qq.com  time: `date` */
#include <bits/stdc++.h>
using namespace std;

#ifndef DEBUG
#define debug(...)
#endif

const int maxn = 1e6+5,maxe = 1e6+5; //点与边的数量

int n,m;

void init(){
	$0
}

int main(){

	return 0;
}
endsnippet

# code template
snippet ct "代码模板-复杂" b
/*-----------------
* author: `!v g:global_author`
* email: `!v g:global_email`
* time: `date`
* problem: ${1: online_judge}-${2:_id }
*----------------*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

#ifndef DEBUG
#define debug(...)
#endif

template<class T>
void read(T &a){
    a = 0;T flag = 1; char ch = getchar();
    while( ch < '0' || ch > '9'){ if( ch == '-') flag = -1; ch = getchar(); }
    while( ch >= '0' && ch <= '9'){ a = a*10 + ch-'0'; ch = getchar(); }
    a*=flag;
}

/* ======= 全局变量 =======*/
const int maxn = 1e6+5,maxe = 1e6+5; //点与边的数量
int n,m;
$0

/* ======= 全局变量 END =======*/
void init(){

}


int main(){
	clock_t program_start_clock = clock(); //开始记时
	//===================
	init();

	//=================== 
	fprintf(stderr,"\n Total Time: %lf ms",double(clock()-program_start_clock)/(CLOCKS_PER_SEC / 1000));
	return 0;
}
endsnippet

# memset
snippet "mem (\S+) (\S+)" "memset a 0" br
memset(${1:`!p snip.rv=match.group(1)`},`!p snip.rv=match.group(2)`,sizeof($1));
endsnippet



snippet maxn "maxn" b
const int max${1:n} = 1e${2:5}+5;
endsnippet

snippet double_max "double max" b
/*
* 最大值: 
*   - 0x7f
*   - 0x42
*   - 0x43
* 最小值:
*   - 0xfe
*   - 0xc2
*/
endsnippet

snippet st "struct" b 
struct ${1:node} {
	$0
};
endsnippet



### =======  调试相关 =======

snippet DD "#define DEBUG" b
#define DEBUG
${0}
endsnippet

snippet dd "debug" b
#define debug(...) fprintf(stderr, __VA_ARGS__)
endsnippet

snippet debug "#ifdef DEBUG" b
#ifdef DEBUG
	${0}
#endif
endsnippet

# printf
# d[flag] [t1] [t1] [t3] [blank]
snippet "d(\w+)? ((\S+ )*\S+)( )?" "debug printf" br
debug("${1:`!p snip.rv=tranFlag(match.group(1),match.group(2),match.group(4))`}${2:\n}",`!p snip.rv=tranSeq(match.group(2))`);
endsnippet

# debug_info
# D[flag] [t1] [t1] [t3] [blank]
snippet "D(\w+)? ((\S+ )*\S+)( )?" "debug printf" br
debug_info("${1:`!p snip.rv=tranFlag(match.group(1),match.group(2),match.group(4))`}${2:\n}",`!p snip.rv=tranSeq(match.group(2))`);
endsnippet

